#include <iostream>
#include <cmath>
#define ll long long

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	ll dp[n];
	cin >> dp[0];
	ll ret = dp[0];
	for(int i = 1; i < n; ++i){
		int num;
		cin >> num;
		if(dp[i-1] > 0){
			dp[i] = num + dp[i-1];
		}else{
			dp[i] = num;
		}
		ret = max(ret,dp[i]);
	}
	
	cout << ret;
	
	return 0;
}

